#include "TcpServer.h"
#include "Daemon.h"
#include <memory>

using namespace std;
using namespace server;

static void usage(const string& process) {
    cout << "\nusage:\n\t" << process << " local_port\n" << endl;
}

//@usage ./TcpServer local_port
int main(int argc, char** argv) {
    if (argc != 2) {
        usage(argv[0]);
        exit(USAGE_ERR);
    }

    uint16_t port = (uint16_t)atoi(argv[1]);

    unique_ptr<TcpServer> tcp_server(new TcpServer(port));
    tcp_server->initServer();

    myDaemon(); // 将服务端进程变为守护进程

    tcp_server->start();
    
    return 0;
}